#ifndef _ENEMY_C
#define _ENEMY_C

#include "enemy.h"

//Functions
void init_enemies(int amount){
 int i,j,k;
 if(amount>MAX_ENEMY)amount=MAX_ENEMY;
 for(i=0;i<MAX_ENEMY;i++){
   wipe_enemy(i);
   kill_enemy_shot(i);
 }
 for(i=0;i<amount;i++){
   enemy[i].cur_x=(rand()%560)+17;
   enemy[i].cur_y=(rand()%300)+17;
   enemy[i].x1=enemy[i].cur_x+3;
   enemy[i].x2=enemy[i].cur_x+58;
   enemy[i].y1=enemy[i].cur_y+12;
   enemy[i].y2=enemy[i].cur_y+58;
   enemy[i].id=i;
   enemy[i].spr=ENEMY_STAND;
   enemy[i].alive=1;
   if(game_mode)enemy[i].energy=enemy_energy;
   else enemy[i].energy=1;
   enemy[i].hit=0;
   enemy[i].dying=0;
   if(enemy[i].cur_x<320)enemy[i].dir=RIGHT;
   else enemy[i].dir=LEFT;
   enemy[i].turn=0;
   enemy[i].mov=0;
   enemy[i].mov_max=(rand()%100)+1;
   enemy[i].mov_dir=(rand()%4);
   enemy[i].wait=enemy[i].mov_max+(rand()%200)+1;
   enemy[i].stop_action=(rand()%2)+1;
   enemy[i].shoot=0;
   enemy[i].shoot_count=0;
   for(j=0;j<25;j++){
    for(k=0;k<45;k++){
     if(tiles[j][k].att!=0){
      if(tile_col_enemy(tiles[j][k],enemy[i])){
       wipe_enemy(enemy[i].id);
      }    
     }    
    }
   }
   for(j=0;j<amount;j++){
    if(enemy[i].alive&&enemy[i].id!=enemy[j].id){
     if(enemy_col_enemy(enemy[i],enemy[j])){
        wipe_enemy(enemy[i].id);
     }
    }
  } 
 }             
}       

void draw_enemies(int amount){
  int i;
  if(amount>MAX_ENEMY)amount=MAX_ENEMY;
  for(i=0;i<amount;i++){
   if(enemy[i].alive){
    switch (enemy[i].dir){
        case LEFT:
        draw_sprite_h_flip(buffer,(BITMAP *) enemy_sprites[enemy[i].spr].dat,enemy[i].cur_x, enemy[i].cur_y);
        break;
        case RIGHT:
        draw_sprite(buffer,(BITMAP *) enemy_sprites[enemy[i].spr].dat, enemy[i].cur_x, enemy[i].cur_y);
        break;
    } 
    if(show_rects)rect(buffer,enemy[i].x1,enemy[i].y1,enemy[i].x2,enemy[i].y2,makecol(255,255,255));     
   }      
  }     
}

void move_enemies(int amount,float vel){
    int i,j,k; 
    if(amount>MAX_ENEMY)amount=MAX_ENEMY;
    for(i=0;i<amount;i++){
     if(!enemy[i].shoot&&enemy[i].alive&&!enemy[i].dying){   
        enemy[i].mov++;
        if(enemy[i].mov<enemy[i].mov_max){
            if(enemy[i].mov>=0&&enemy[i].mov<5)enemy[i].spr=ENEMY_WALK0;
            if(enemy[i].mov>=5&&enemy[i].mov<10)enemy[i].spr=ENEMY_WALK1;
            if(enemy[i].mov>=10&&enemy[i].mov<15)enemy[i].spr=ENEMY_WALK2;
            if(enemy[i].mov>=15&&enemy[i].mov<20)enemy[i].spr=ENEMY_WALK3;
            if(enemy[i].mov>=20&&enemy[i].mov<25)enemy[i].spr=ENEMY_WALK4;
            if(enemy[i].mov>=25&&enemy[i].mov<30)enemy[i].spr=ENEMY_WALK5;
            if(enemy[i].mov>=30&&enemy[i].mov<35)enemy[i].spr=ENEMY_WALK6;
            if(enemy[i].mov>=35&&enemy[i].mov<40)enemy[i].spr=ENEMY_WALK7;
            if(enemy[i].mov>=40&&enemy[i].mov<45)enemy[i].spr=ENEMY_WALK8;
            if(enemy[i].mov>=45&&enemy[i].mov<50)enemy[i].spr=ENEMY_WALK9;
            if(enemy[i].mov>=50&&enemy[i].mov<55)enemy[i].spr=ENEMY_WALK0;
            if(enemy[i].mov>=55&&enemy[i].mov<60)enemy[i].spr=ENEMY_WALK1;
            if(enemy[i].mov>=60&&enemy[i].mov<65)enemy[i].spr=ENEMY_WALK2;
            if(enemy[i].mov>=65&&enemy[i].mov<70)enemy[i].spr=ENEMY_WALK3;
            if(enemy[i].mov>=70&&enemy[i].mov<75)enemy[i].spr=ENEMY_WALK4;
            if(enemy[i].mov>=75&&enemy[i].mov<80)enemy[i].spr=ENEMY_WALK5;
            if(enemy[i].mov>=80&&enemy[i].mov<85)enemy[i].spr=ENEMY_WALK6;
            if(enemy[i].mov>=85&&enemy[i].mov<90)enemy[i].spr=ENEMY_WALK7;
            if(enemy[i].mov>=90&&enemy[i].mov<95)enemy[i].spr=ENEMY_WALK8;
            if(enemy[i].mov>=95&&enemy[i].mov<100)enemy[i].spr=ENEMY_WALK9;
            switch(enemy[i].mov_dir){
                case LEFT:
                    enemy[i].dir=LEFT;
                    enemy[i].cur_x-=vel;enemy[i].x1-=vel;enemy[i].x2-=vel;
                    if(enemy[i].cur_x<0){
                        enemy[i].cur_x+=vel;enemy[i].x1+=vel;enemy[i].x2+=vel;enemy[i].mov=enemy[i].mov_max;
                    }    
                    for(j=0;j<25;j++){
                     for(k=0;k<45;k++){
                       if(tiles[j][k].att!=0){
                        if(tile_col_enemy(tiles[j][k],enemy[i])){
                          enemy[i].cur_x+=vel;enemy[i].x1+=vel;enemy[i].x2+=vel;enemy[i].mov=enemy[i].mov_max;
                          break;
                        }    
                       }    
                     }
                    }
                    for(j=0;j<amount;j++){
                     if(enemy[j].alive&&enemy[j].id!=enemy[i].id){
                      if(enemy_col_enemy(enemy[j],enemy[i])){
                        enemy[i].cur_x+=vel;enemy[i].x1+=vel;enemy[i].x2+=vel;enemy[i].mov=enemy[i].mov_max;
                        break;
                      }
                     }
                    }
                    break;
                case RIGHT:
                    enemy[i].dir=RIGHT;
                    enemy[i].cur_x+=vel;enemy[i].x1+=vel;enemy[i].x2+=vel;
                    if(enemy[i].cur_x>580){
                        enemy[i].cur_x-=vel;enemy[i].x1-=vel;enemy[i].x2-=vel;enemy[i].mov=enemy[i].mov_max;
                    }    
                    for(j=0;j<25;j++){
                     for(k=0;k<45;k++){
                       if(tiles[j][k].att!=0){
                        if(tile_col_enemy(tiles[j][k],enemy[i])){
                          enemy[i].cur_x-=vel;enemy[i].x1-=vel;enemy[i].x2-=vel;enemy[i].mov=enemy[i].mov_max;
                          break;
                        }    
                       }    
                     }
                    }
                    for(j=0;j<amount;j++){
                     if(enemy[j].alive&&enemy[j].id!=enemy[i].id){
                      if(enemy_col_enemy(enemy[j],enemy[i])){
                        enemy[i].cur_x-=vel;enemy[i].x1-=vel;enemy[i].x2-=vel;enemy[i].mov=enemy[i].mov_max;
                        break;
                      }
                     }
                    }
                    break;
                case UP:
                    enemy[i].cur_y-=vel;enemy[i].y1-=vel;enemy[i].y2-=vel;
                    if(enemy[i].cur_y<0){
                        enemy[i].cur_y+=vel;enemy[i].y1+=vel;enemy[i].y2+=vel;enemy[i].mov=enemy[i].mov_max;
                    }    
                    for(j=0;j<25;j++){
                     for(k=0;k<45;k++){
                       if(tiles[j][k].att!=0){
                        if(tile_col_enemy(tiles[j][k],enemy[i])){
                          enemy[i].cur_y+=vel;enemy[i].y1+=vel;enemy[i].y2+=vel;enemy[i].mov=enemy[i].mov_max;
                          break;
                        }    
                       }    
                     }
                    }
                    for(j=0;j<amount;j++){
                     if(enemy[j].alive&&enemy[j].id!=enemy[i].id){
                      if(enemy_col_enemy(enemy[j],enemy[i])){
                        enemy[i].cur_y+=vel;enemy[i].y1+=vel;enemy[i].y2+=vel;enemy[i].mov=enemy[i].mov_max;
                        break;
                      }
                     }
                    }
                    break;
                case DOWN:
                    enemy[i].cur_y+=vel;enemy[i].y1+=vel;enemy[i].y2+=vel;
                    if(enemy[i].cur_y>340){
                        enemy[i].cur_y-=vel;enemy[i].y1-=vel;enemy[i].y2-=vel;enemy[i].mov=enemy[i].mov_max;
                    }    
                    for(j=0;j<25;j++){
                     for(k=0;k<45;k++){
                       if(tiles[j][k].att!=0){
                        if(tile_col_enemy(tiles[j][k],enemy[i])){
                          enemy[i].cur_y-=vel;enemy[i].y1-=vel;enemy[i].y2-=vel;enemy[i].mov=enemy[i].mov_max;
                          break;
                        }    
                       }    
                     }
                    }
                    for(j=0;j<amount;j++){
                     if(enemy[j].alive&&enemy[j].id!=enemy[i].id){
                      if(enemy_col_enemy(enemy[j],enemy[i])){
                        enemy[i].cur_y-=vel;enemy[i].y1-=vel;enemy[i].y2-=vel;enemy[i].mov=enemy[i].mov_max;
                        break;
                      }
                     }
                    }
                    break;
            }
        }        
        if(enemy[i].mov>enemy[i].mov_max&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait){
            switch(enemy[i].stop_action){
                case SCRATCH:
                    if(enemy[i].mov>=enemy[i].mov_max&&enemy[i].mov<enemy[i].mov_max+10)enemy[i].spr=ENEMY_SCRATCH0;
                    if(enemy[i].mov>=enemy[i].mov_max+10&&enemy[i].mov<enemy[i].mov_max+20)enemy[i].spr=ENEMY_SCRATCH1;
                    if(enemy[i].mov>=enemy[i].mov_max+20&&enemy[i].mov<enemy[i].mov_max+30)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+30&&enemy[i].mov<enemy[i].mov_max+40)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+40&&enemy[i].mov<enemy[i].mov_max+50)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+50&&enemy[i].mov<enemy[i].mov_max+60)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+60&&enemy[i].mov<enemy[i].mov_max+70)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+70&&enemy[i].mov<enemy[i].mov_max+80)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+80&&enemy[i].mov<enemy[i].mov_max+90)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+90&&enemy[i].mov<enemy[i].mov_max+100)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+100&&enemy[i].mov<enemy[i].mov_max+110)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+110&&enemy[i].mov<enemy[i].mov_max+120)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+120&&enemy[i].mov<enemy[i].mov_max+130)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+130&&enemy[i].mov<enemy[i].mov_max+140)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+140&&enemy[i].mov<enemy[i].mov_max+150)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+150&&enemy[i].mov<enemy[i].mov_max+160)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+160&&enemy[i].mov<enemy[i].mov_max+170)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+170&&enemy[i].mov<enemy[i].mov_max+180)enemy[i].spr=ENEMY_SCRATCH3;
                    if(enemy[i].mov>=enemy[i].mov_max+180&&enemy[i].mov<enemy[i].mov_max+190)enemy[i].spr=ENEMY_SCRATCH2;
                    if(enemy[i].mov>=enemy[i].mov_max+190&&enemy[i].mov<enemy[i].mov_max+200)enemy[i].spr=ENEMY_SCRATCH3;
                    break;
                case LOOK:
                    if(enemy[i].mov>=enemy[i].mov_max&&enemy[i].mov<enemy[i].mov_max+20)enemy[i].spr=ENEMY_LOOK0;
                    if(enemy[i].mov>=enemy[i].mov_max+20&&enemy[i].mov<enemy[i].mov_max+40)enemy[i].spr=ENEMY_LOOK1;
                    if(enemy[i].mov>=enemy[i].mov_max+40&&enemy[i].mov<enemy[i].mov_max+60)enemy[i].spr=ENEMY_LOOK2;
                    if(enemy[i].mov>=enemy[i].mov_max+60&&enemy[i].mov<enemy[i].mov_max+80)enemy[i].spr=ENEMY_LOOK1;
                    if(enemy[i].mov>=enemy[i].mov_max+80&&enemy[i].mov<enemy[i].mov_max+100)enemy[i].spr=ENEMY_LOOK0;
                    if(enemy[i].mov>=enemy[i].mov_max+100&&enemy[i].mov<enemy[i].mov_max+120){
                        enemy[i].spr=ENEMY_LOOK0;
                        if(!enemy[i].turn){
                            enemy[i].turn=1;
                            if(enemy[i].dir==LEFT)enemy[i].dir=RIGHT;
                            else enemy[i].dir=RIGHT;
                        }    
                    }    
                    if(enemy[i].mov>=enemy[i].mov_max+120&&enemy[i].mov<enemy[i].mov_max+140){enemy[i].spr=ENEMY_LOOK2;enemy[i].turn=0;}
                    if(enemy[i].mov>=enemy[i].mov_max+140&&enemy[i].mov<enemy[i].mov_max+160)enemy[i].spr=ENEMY_LOOK1;
                    if(enemy[i].mov>=enemy[i].mov_max+160&&enemy[i].mov<enemy[i].mov_max+180)enemy[i].spr=ENEMY_LOOK0;
                    if(enemy[i].mov>=enemy[i].mov_max+180&&enemy[i].mov<enemy[i].mov_max+200){
                        enemy[i].spr=ENEMY_LOOK0;
                        if(!enemy[i].turn){
                            enemy[i].turn=1;
                            if(enemy[i].dir==LEFT)enemy[i].dir=RIGHT;
                            else enemy[i].dir=RIGHT;
                        }    
                    } 
                    break;
            }
        }
        if(enemy[i].mov==enemy[i].mov_max+enemy[i].wait){
            enemy[i].mov=0;
            enemy[i].turn=0;
            enemy[i].mov_max=(rand()%100)+1;
            enemy[i].mov_dir=(rand()%4);
            enemy[i].wait=enemy[i].mov_max+(rand()%200)+1;
            enemy[i].stop_action=(rand()%2)+1;
        }
     }
     else { 
       enemy[i].shoot_count++;
       if(enemy[i].shoot_count<5)enemy[i].spr=ENEMY_SHOOT0;
       if(enemy[i].shoot_count>5&&enemy[i].shoot_count<15)enemy[i].spr=ENEMY_SHOOT1;
       if(enemy[i].shoot_count>25){
           enemy[i].shoot=0;enemy[i].shoot_count=0;
       }    
     }
     if(enemy[i].dying){
         enemy[i].mov++;
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait+30)enemy[i].spr=ENEMY_DIE0;    
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait+30&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait+40)enemy[i].spr=ENEMY_DIE1;    
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait+40&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait+45)enemy[i].spr=ENEMY_DIE2;   
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait+45&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait+50)enemy[i].spr=ENEMY_DIE3;    
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait+50&&enemy[i].mov<enemy[i].mov_max+enemy[i].wait+55)enemy[i].spr=ENEMY_DIE4; 
         if(enemy[i].mov>enemy[i].mov_max+enemy[i].wait+55){
             enemy[i].cur_x=0;
             enemy[i].cur_y=0;
             enemy[i].spr=0;
             enemy[i].alive=0;
             enemy[i].dying=0;
             enemy[i].mov=0;
             enemy[i].mov_max=0;
             enemy[i].mov_dir=0;
             enemy[i].wait=0;
             enemy[i].stop_action=0;
             enemy[i].shoot=0;
             enemy[i].shoot_count=0;
         }        
     }
    }            
}

void enemy_shoot(int amount,int p_x,int p_y){
    int i;
    if(amount>MAX_ENEMY)amount=MAX_ENEMY;
    for(i=0;i<amount;i++){
      if(!enemy_shot[i].alive&&!enemy[i].shoot&&enemy[i].alive&&!enemy[i].dying){
        if(enemy[i].cur_x>p_x&&enemy[i].dir==LEFT){
            if(p_y>enemy[i].cur_y&&p_y<enemy[i].cur_y+30){
                enemy[i].shoot=1;
                enemy_shot[i].id=enemy[i].id;
                enemy_shot[i].alive=1;
                enemy_shot[i].cur_x=enemy[i].cur_x;
                enemy_shot[i].cur_y=enemy[i].cur_y;
                enemy_shot[i].x1=enemy_shot[i].cur_x+23;enemy_shot[i].x2=enemy_shot[i].cur_x+37;
                enemy_shot[i].y1=enemy_shot[i].cur_y+24;enemy_shot[i].y2=enemy_shot[i].cur_y+37;
                enemy_shot[i].spr=ENEMY_SHOT0;
                enemy_shot[i].glow_count=0;
                enemy_shot[i].dir=LEFT;
                play_sample(game_sound[E_SHOT_SOUND].dat,sound_vol,128,1000,0);
            }
        }
        if(enemy[i].cur_x<p_x&&enemy[i].dir==RIGHT){
            if(p_y>enemy[i].cur_y&&p_y<enemy[i].cur_y+30){
                enemy[i].shoot=1;
                enemy_shot[i].id=enemy[i].id;
                enemy_shot[i].alive=1;
                enemy_shot[i].cur_x=enemy[i].cur_x;
                enemy_shot[i].cur_y=enemy[i].cur_y;
                enemy_shot[i].x1=enemy_shot[i].cur_x+23;enemy_shot[i].x2=enemy_shot[i].cur_x+37;
                enemy_shot[i].y1=enemy_shot[i].cur_y+24;enemy_shot[i].y2=enemy_shot[i].cur_y+37;
                enemy_shot[i].spr=ENEMY_SHOT0;
                enemy_shot[i].glow_count=0;
                enemy_shot[i].dir=RIGHT;
                play_sample(game_sound[E_SHOT_SOUND].dat,sound_vol,128,1000,0);
            }
        }
        if(enemy[i].cur_y>p_y){
            if(p_x>enemy[i].cur_x&&p_x<enemy[i].cur_x+30){
                enemy[i].shoot=1;
                enemy_shot[i].id=enemy[i].id;
                enemy_shot[i].alive=1;
                enemy_shot[i].cur_x=enemy[i].cur_x;
                enemy_shot[i].cur_y=enemy[i].cur_y;
                enemy_shot[i].x1=enemy_shot[i].cur_x+23;enemy_shot[i].x2=enemy_shot[i].cur_x+37;
                enemy_shot[i].y1=enemy_shot[i].cur_y+24;enemy_shot[i].y2=enemy_shot[i].cur_y+37;
                enemy_shot[i].spr=ENEMY_SHOT0;
                enemy_shot[i].glow_count=0;
                enemy_shot[i].dir=UP;
                play_sample(game_sound[E_SHOT_SOUND].dat,sound_vol,128,1000,0);
            }
        }
        if(enemy[i].cur_y<p_y){
            if(p_x>enemy[i].cur_x&&p_x<enemy[i].cur_x+30){
                enemy[i].shoot=1;
                enemy_shot[i].id=enemy[i].id;
                enemy_shot[i].alive=1;
                enemy_shot[i].cur_x=enemy[i].cur_x;
                enemy_shot[i].cur_y=enemy[i].cur_y;
                enemy_shot[i].x1=enemy_shot[i].cur_x+23;enemy_shot[i].x2=enemy_shot[i].cur_x+37;
                enemy_shot[i].y1=enemy_shot[i].cur_y+24;enemy_shot[i].y2=enemy_shot[i].cur_y+37;
                enemy_shot[i].spr=ENEMY_SHOT0;
                enemy_shot[i].glow_count=0;
                enemy_shot[i].dir=DOWN;
                play_sample(game_sound[E_SHOT_SOUND].dat,sound_vol,128,1000,0);
            }
        }
      }    
    } 
} 

void update_enemy_shot(int amount, float vel){
    int i,j,k;
    if(amount>MAX_ENEMY)amount=MAX_ENEMY;
    for(i=0;i<amount;i++){
      if(enemy_shot[i].alive){
          switch(enemy_shot[i].dir){
              case LEFT:
                  enemy_shot[i].cur_x-=vel;
                  enemy_shot[i].x1-=vel;
                  enemy_shot[i].x2-=vel;
                  if(enemy_shot[i].cur_x<-60)kill_enemy_shot(enemy_shot[i].id);
                  break;
              case RIGHT:
                  enemy_shot[i].cur_x+=vel;
                  enemy_shot[i].x1+=vel;
                  enemy_shot[i].x2+=vel;
                  if(enemy_shot[i].cur_x>700)kill_enemy_shot(enemy_shot[i].id);
                  break;
              case UP:
                  enemy_shot[i].cur_y-=vel;
                  enemy_shot[i].y1-=vel;
                  enemy_shot[i].y2-=vel;
                  if(enemy_shot[i].cur_y<-60)kill_enemy_shot(enemy_shot[i].id);
                  break;
              case DOWN:
                  enemy_shot[i].cur_y+=vel;
                  enemy_shot[i].y1+=vel;
                  enemy_shot[i].y2+=vel;
                  if(enemy_shot[i].cur_y>460)kill_enemy_shot(enemy_shot[i].id);
                  break;
          }
          enemy_shot[i].glow_count++;
          if(enemy_shot[i].glow_count>0&&enemy_shot[i].glow_count<10)enemy_shot[i].spr=ENEMY_SHOT0;
          if(enemy_shot[i].glow_count>10&&enemy_shot[i].glow_count<20)enemy_shot[i].spr=ENEMY_SHOT1;
          if(enemy_shot[i].glow_count>20)enemy_shot[i].glow_count=0;
       for(j=0;j<25;j++){
        for(k=0;k<45;k++){
         if(tiles[j][k].att!=0){
          if(tile_col_enemy_shot(tiles[j][k],enemy_shot[i])){
           kill_enemy_shot(enemy_shot[i].id);break;
          }    
         }    
        }
       }
       for(j=0;j<amount;j++){
         if(enemy[j].alive&&enemy_shot[i].id!=enemy[j].id){ 
          if(enemy_col_enemy_shot(enemy[j],enemy_shot[i])){
              enemy[j].energy--;
              if(enemy[j].energy<=0){
                kill_enemy(enemy[j].id);
                if(!game_mode)point_adder+=50;//give_points(50);
              }
              kill_enemy_shot(enemy_shot[i].id);
              break;
          }
         }            
       }
       for(j=0;j<amount;j++){
         if(enemy_shot[j].alive&&enemy_shot[i].id!=enemy_shot[j].id){ 
          if(enemy_shot_col_enemy_shot(enemy_shot[j],enemy_shot[i])){
              kill_enemy_shot(enemy_shot[i].id);
              kill_enemy_shot(enemy_shot[j].id);
              break;
          }
         }            
       }
      }
    }            
}        

void draw_enemy_shot(int amount){
  int i;
  if(amount>MAX_ENEMY)amount=MAX_ENEMY;
  for(i=0;i<amount;i++){
   if(enemy_shot[i].alive){
    draw_sprite(buffer,(BITMAP *) enemy_sprites[enemy_shot[i].spr].dat, enemy_shot[i].cur_x, enemy_shot[i].cur_y);    
    if(show_rects)rect(buffer,enemy_shot[i].x1,enemy_shot[i].y1,enemy_shot[i].x2,enemy_shot[i].y2,makecol(255,255,255));
   }      
  }     
}

void kill_enemy(int id){
    if(enemy[id].mov<=enemy[id].mov_max+enemy[id].wait){
     enemy[id].mov=enemy[id].mov_max+enemy[id].wait+1;  //The actuall killing takes place in the move_enemy function
     enemy[id].x1=0;                                    //This just starts the process some repetitive code......
     enemy[id].x2=0;                                   // I Know..... There's allot :|
     enemy[id].y1=0;
     enemy[id].y2=0;
     enemy[id].dying=1;
     start_enemy_explosion(id);
     play_sample(game_sound[EXPLODE_SOUND].dat,255,128,1000,0);
    }
}

void wipe_enemy(int id){
       enemy[id].cur_x=0;
       enemy[id].cur_y=0;                    //Removes enemy without the animation helpfull for my init
       enemy[id].x1=0;                                    
       enemy[id].x2=0;
       enemy[id].y1=0;
       enemy[id].y2=0;
       enemy[id].spr=0;
       enemy[id].alive=0;
       enemy[id].dying=0;
       enemy[id].mov=0;
       enemy[id].mov_max=0;
       enemy[id].mov_dir=0;
       enemy[id].turn=0;
       enemy[id].wait=0;
       enemy[id].stop_action=0;
       enemy[id].shoot=0;
       enemy[id].shoot_count=0;
}    


void kill_enemy_shot(int id){
    enemy_shot[id].cur_x=0;
    enemy_shot[id].cur_y=0;
    enemy_shot[id].x1=0;
    enemy_shot[id].x2=0;
    enemy_shot[id].y1=0;
    enemy_shot[id].y2=0;
    enemy_shot[id].spr=0;
    enemy_shot[id].alive=0;
    enemy_shot[id].glow_count=0;
    enemy_shot[id].dir=0;
}

void start_enemy_explosion(int id){
    enemy_explosion[id].id=enemy[id].id;
    enemy_explosion[id].x=enemy[id].cur_x-50;
    enemy_explosion[id].y=enemy[id].cur_y-50;
    enemy_explosion[id].alive=1;
    enemy_explosion[id].spr=EXPLODE0;
    enemy_explosion[id].counter=0;
}

void update_enemy_explosion(int amount){
    int i=0;
    if(amount>MAX_ENEMY)amount=MAX_ENEMY;
    for(i=0;i<amount;i++){
     if(enemy_explosion[i].alive){
      enemy_explosion[i].counter++;
      if(enemy_explosion[i].counter>=0&&enemy_explosion[i].counter<2)enemy_explosion[i].spr=EXPLODE0;
      if(enemy_explosion[i].counter>=2&&enemy_explosion[i].counter<4)enemy_explosion[i].spr=EXPLODE1;
      if(enemy_explosion[i].counter>=4&&enemy_explosion[i].counter<6)enemy_explosion[i].spr=EXPLODE2;
      if(enemy_explosion[i].counter>=6&&enemy_explosion[i].counter<8)enemy_explosion[i].spr=EXPLODE3;
      if(enemy_explosion[i].counter>=8&&enemy_explosion[i].counter<10)enemy_explosion[i].spr=EXPLODE4;
      if(enemy_explosion[i].counter>=10&&enemy_explosion[i].counter<12)enemy_explosion[i].spr=EXPLODE5;
      if(enemy_explosion[i].counter>=12&&enemy_explosion[i].counter<14)enemy_explosion[i].spr=EXPLODE6;
      if(enemy_explosion[i].counter>=14&&enemy_explosion[i].counter<16)enemy_explosion[i].spr=EXPLODE7;
      if(enemy_explosion[i].counter>=16&&enemy_explosion[i].counter<18)enemy_explosion[i].spr=EXPLODE8;
      if(enemy_explosion[i].counter>=18&&enemy_explosion[i].counter<20)enemy_explosion[i].spr=EXPLODE9;
      if(enemy_explosion[i].counter>=20&&enemy_explosion[i].counter<22)enemy_explosion[i].spr=EXPLODE10;
      if(enemy_explosion[i].counter>=22&&enemy_explosion[i].counter<24)enemy_explosion[i].spr=EXPLODE11;
      if(enemy_explosion[i].counter>=24&&enemy_explosion[i].counter<26)enemy_explosion[i].spr=EXPLODE12;
      if(enemy_explosion[i].counter>=26&&enemy_explosion[i].counter<28)enemy_explosion[i].spr=EXPLODE13;
      if(enemy_explosion[i].counter>=28&&enemy_explosion[i].counter<30)enemy_explosion[i].spr=EXPLODE14;
      if(enemy_explosion[i].counter>=30&&enemy_explosion[i].counter<32)enemy_explosion[i].spr=EXPLODE15;
      if(enemy_explosion[i].counter>=32&&enemy_explosion[i].counter<34)enemy_explosion[i].spr=EXPLODE16;
      if(enemy_explosion[i].counter>=34&&enemy_explosion[i].counter<36)enemy_explosion[i].spr=EXPLODE17;
      if(enemy_explosion[i].counter>=36&&enemy_explosion[i].counter<38)enemy_explosion[i].spr=EXPLODE18;
      if(enemy_explosion[i].counter>=38&&enemy_explosion[i].counter<40)enemy_explosion[i].spr=EXPLODE19;
      if(enemy_explosion[i].counter>=40&&enemy_explosion[i].counter<42)enemy_explosion[i].spr=EXPLODE20;
      if(enemy_explosion[i].counter>=42&&enemy_explosion[i].counter<44)enemy_explosion[i].spr=EXPLODE21;
      if(enemy_explosion[i].counter>=44&&enemy_explosion[i].counter<46)enemy_explosion[i].spr=EXPLODE22;
      if(enemy_explosion[i].counter>=46&&enemy_explosion[i].counter<48)enemy_explosion[i].spr=EXPLODE23;
      if(enemy_explosion[i].counter>=48&&enemy_explosion[i].counter<50)enemy_explosion[i].spr=EXPLODE24;
      if(enemy_explosion[i].counter>=50&&enemy_explosion[i].counter<52)enemy_explosion[i].spr=EXPLODE25;
      if(enemy_explosion[i].counter>=52&&enemy_explosion[i].counter<54)enemy_explosion[i].spr=EXPLODE26;
      if(enemy_explosion[i].counter>=54&&enemy_explosion[i].counter<56)enemy_explosion[i].spr=EXPLODE27;
      if(enemy_explosion[i].counter>=56&&enemy_explosion[i].counter<58)enemy_explosion[i].spr=EXPLODE28;
      if(enemy_explosion[i].counter>=58&&enemy_explosion[i].counter<60)enemy_explosion[i].spr=EXPLODE29;
      if(enemy_explosion[i].counter>=60&&enemy_explosion[i].counter<62)enemy_explosion[i].spr=EXPLODE30;
      if(enemy_explosion[i].counter>=62&&enemy_explosion[i].counter<64)enemy_explosion[i].spr=EXPLODE31;
      if(enemy_explosion[i].counter>=64&&enemy_explosion[i].counter<66)enemy_explosion[i].spr=EXPLODE32;
      if(enemy_explosion[i].counter>=66&&enemy_explosion[i].counter<68)enemy_explosion[i].spr=EXPLODE33;
      if(enemy_explosion[i].counter>=68&&enemy_explosion[i].counter<70)enemy_explosion[i].spr=EXPLODE34;
      if(enemy_explosion[i].counter>=70&&enemy_explosion[i].counter<72)enemy_explosion[i].spr=EXPLODE35;
      if(enemy_explosion[i].counter>=72&&enemy_explosion[i].counter<74)enemy_explosion[i].spr=EXPLODE36;
      if(enemy_explosion[i].counter>=74&&enemy_explosion[i].counter<76)enemy_explosion[i].spr=EXPLODE37;
      if(enemy_explosion[i].counter>=76&&enemy_explosion[i].counter<78)enemy_explosion[i].spr=EXPLODE38;
      if(enemy_explosion[i].counter>=78&&enemy_explosion[i].counter<80)enemy_explosion[i].spr=EXPLODE39;
      if(enemy_explosion[i].counter>=80&&enemy_explosion[i].counter<82)enemy_explosion[i].spr=EXPLODE40;
      if(enemy_explosion[i].counter>=82&&enemy_explosion[i].counter<84)enemy_explosion[i].spr=EXPLODE41;
      if(enemy_explosion[i].counter>=84){
        enemy_explosion[i].x=0;
        enemy_explosion[i].y=0;
        enemy_explosion[i].alive=0;
        enemy_explosion[i].spr=EXPLODE0;
        enemy_explosion[i].counter=0;
      }    
     }
    }    
}

    
void draw_enemy_explosion(int amount){ 
  int i;
  if(amount>MAX_ENEMY)amount=MAX_ENEMY;  
  for(i=0;i<amount;i++){
    if(enemy_explosion[i].alive){
        draw_sprite(buffer,(BITMAP *) explode_sprites[enemy_explosion[i].spr].dat, enemy_explosion[i].x, enemy_explosion[i].y);  
    }    
  }    
}
   
void init_ball(int amount,int wait_time){
    int i,loc;
    if(amount>MAX_BALLS)amount=MAX_BALLS;
    for(i=0;i<amount;i++){
       loc=rand()%4;
       switch(loc){
           case 0:  //Left side
             ball[i].cur_x=-100;
             ball[i].cur_y=138;                    //Initialize the ball to the basics
             ball[i].dir=RIGHT;
             break;
           case 1:  //Right side
             ball[i].cur_x=640;
             ball[i].cur_y=138;                    //Initialize the ball to the basics
             ball[i].dir=LEFT;
             break;
           case 2:  //Top
             ball[i].cur_x=270;
             ball[i].cur_y=-125;                      //Initialize the ball to the basics
             break;
           case 3:  //Bottom
             ball[i].cur_x=270;
             ball[i].cur_y=400;                    //Initialize the ball to the basics
             break;  
       }
       ball[i].x1=ball[i].cur_x+10;                                    
       ball[i].x2=ball[i].cur_x+115;
       ball[i].y1=ball[i].cur_y+10;
       ball[i].y2=ball[i].cur_y+90;
       ball[i].id=i;
       ball[i].spr=BALL_UP0;
       ball[i].alive=0;
       ball[i].dying=0;
       ball[i].mov=0;
       ball[i].mov_max=0;
       ball[i].mov_dir=0;
       ball[i].wait=(rand()%500)+wait_time;
       ball[i].stop_action=0;
       ball[i].shoot=0;
       ball[i].shoot_count=0;    
   }    
}

       
void draw_ball(int amount){
    int i;
    if(amount>MAX_BALLS)amount=MAX_BALLS;  
    for(i=0;i<amount;i++){
       if(ball[i].alive){
           switch(ball[i].dir){
               case LEFT:
                   draw_sprite_h_flip(buffer,(BITMAP *) ball_sprites[ball[i].spr].dat, ball[i].cur_x, ball[i].cur_y);
                   break;
               case RIGHT:
                   draw_sprite(buffer,(BITMAP *) ball_sprites[ball[i].spr].dat, ball[i].cur_x, ball[i].cur_y);
                   break;
           }   
           if(show_rects)rect(buffer,ball[i].x1,ball[i].y1,ball[i].x2,ball[i].y2,makecol(255,255,255));   
       }    
    }    
}    

void move_ball(int amount,float vel,int x,int y){
    int i,j,check=0;
    if(amount>MAX_BALLS)amount=MAX_BALLS;
    for(i=0;i<amount;i++){
     if(ball[i].wait>0)ball[i].wait--;
     if(ball[i].wait==1)play_sample(game_sound[BALL_ALIVE].dat,sound_vol,128,1000,0);
     if(ball[i].wait==0)ball[i].alive=1; 
     if(ball[i].alive&&!ball[i].dying){
      ball[i].mov++;       
        if(ball[i].cur_x<x-30){
            ball[i].dir=RIGHT;
            ball[i].cur_x+=vel;ball[i].x1+=vel;ball[i].x2+=vel;
        }    
        if(ball[i].cur_x>x-30){
            ball[i].dir=LEFT;
            ball[i].cur_x-=vel;ball[i].x1-=vel;ball[i].x2-=vel;
        }
        if(ball[i].cur_y<y-5){
            ball[i].mov_dir=DOWN;
            ball[i].cur_y+=vel;ball[i].y1+=vel;ball[i].y2+=vel;
        }
        if(ball[i].cur_y>y-5){
            ball[i].mov_dir=UP;
            ball[i].cur_y-=vel;ball[i].y1-=vel;ball[i].y2-=vel;
        }
        switch(ball[i].mov_dir){
            case UP:
                if(ball[i].mov>0&&ball[i].mov<5)ball[i].spr=BALL_UP0;
                if(ball[i].mov>5&&ball[i].mov<10)ball[i].spr=BALL_UP1;
                if(ball[i].mov>10&&ball[i].mov<15)ball[i].spr=BALL_UP2;
                if(ball[i].mov>15&&ball[i].mov<20)ball[i].spr=BALL_UP3;
                if(ball[i].mov==20)ball[i].mov=0;
                break;
            case DOWN:
                if(ball[i].mov>0&&ball[i].mov<5)ball[i].spr=BALL_DOWN0;
                if(ball[i].mov>5&&ball[i].mov<10)ball[i].spr=BALL_DOWN1;
                if(ball[i].mov>10&&ball[i].mov<15)ball[i].spr=BALL_DOWN2;
                if(ball[i].mov>15&&ball[i].mov<20)ball[i].spr=BALL_DOWN3;
                if(ball[i].mov==20)ball[i].mov=0;
                break;
        } 
     }
     if(ball[i].dying){
         ball[i].mov++;
         if(ball[i].mov>0&&ball[i].mov<5)ball[i].spr=BALL_DOWN0;
         if(ball[i].mov>5&&ball[i].mov<10)ball[i].spr=BALL_DOWN1;
         if(ball[i].mov>10&&ball[i].mov<15)ball[i].spr=BALL_DOWN2;
         if(ball[i].mov>15&&ball[i].mov<20)ball[i].spr=BALL_DOWN3;
         if(ball[i].mov==20){
             ball[i].cur_x=0;
             ball[i].cur_y=0;
             ball[i].spr=0;
             ball[i].alive=0;
             ball[i].dying=0;
             ball[i].mov=0;
             ball[i].mov_max=0;
             ball[i].mov_dir=0;
             ball[i].wait=-1;
             ball[i].stop_action=0;
             ball[i].shoot=0;
             ball[i].shoot_count=0;
         }    
     }
     if(!ball[i].alive&&ball[i].wait==-1)check++;
     if(check==amount){
         init_ball(amount,ball_time);
         check=0;
     }    
     for(j=0;j<MAX_ENEMY;j++){
         if(enemy[j].alive&&ball[i].alive){ 
          if(enemy_col_enemy(enemy[j],ball[i])){
              enemy[j].energy--;
              if(enemy[j].energy<=0){
                kill_enemy(enemy[j].id);
                if(!game_mode)point_adder+=50;//give_points(50);
              }
              break;
          }
         }            
     }  
     for(j=0;j<MAX_ENEMY;j++){
         if(enemy_shot[j].alive){ 
          if(enemy_col_enemy_shot(ball[i],enemy_shot[j])){
           kill_enemy_shot(enemy_shot[j].id);break;
          }
         }            
     }  
    }    
}        
void kill_ball(int id){
     stop_sample(game_sound[BALL_ALIVE].dat);
     ball[id].mov=0;  //The actuall killing takes place in the move_enemy function
     ball[id].x1=640;                                    //This just starts the process some repetitive code......
     ball[id].x2=640;                                   // I Know..... There's allot :|
     ball[id].y1=0;
     ball[id].y2=0;
     ball[id].dying=1;
     start_ball_explosion(id);
     play_sample(game_sound[ALT_EXPLODE_SOUND].dat,255,128,1000,0);
}    
void start_ball_explosion(int id){
    ball_explosion[id].id=ball[id].id;
    ball_explosion[id].x=ball[id].cur_x-20;
    ball_explosion[id].y=ball[id].cur_y-20;
    ball_explosion[id].alive=1;
    ball_explosion[id].spr=EXPLODE0;
    ball_explosion[id].counter=0;
}
void update_ball_explosion(int amount){
    int i=0;
    if(amount>MAX_BALLS)amount=MAX_BALLS;
    for(i=0;i<amount;i++){
     if(ball_explosion[i].alive){
      ball_explosion[i].counter++;
      if(ball_explosion[i].counter>=0&&ball_explosion[i].counter<2)ball_explosion[i].spr=EXPLODE0;
      if(ball_explosion[i].counter>=2&&ball_explosion[i].counter<4)ball_explosion[i].spr=EXPLODE1;
      if(ball_explosion[i].counter>=4&&ball_explosion[i].counter<6)ball_explosion[i].spr=EXPLODE2;
      if(ball_explosion[i].counter>=6&&ball_explosion[i].counter<8)ball_explosion[i].spr=EXPLODE3;
      if(ball_explosion[i].counter>=8&&ball_explosion[i].counter<10)ball_explosion[i].spr=EXPLODE4;
      if(ball_explosion[i].counter>=10&&ball_explosion[i].counter<12)ball_explosion[i].spr=EXPLODE5;
      if(ball_explosion[i].counter>=12&&ball_explosion[i].counter<14)ball_explosion[i].spr=EXPLODE6;
      if(ball_explosion[i].counter>=14&&ball_explosion[i].counter<16)ball_explosion[i].spr=EXPLODE7;
      if(ball_explosion[i].counter>=16&&ball_explosion[i].counter<18)ball_explosion[i].spr=EXPLODE8;
      if(ball_explosion[i].counter>=18&&ball_explosion[i].counter<20)ball_explosion[i].spr=EXPLODE9;
      if(ball_explosion[i].counter>=20&&ball_explosion[i].counter<22)ball_explosion[i].spr=EXPLODE10;
      if(ball_explosion[i].counter>=22&&ball_explosion[i].counter<24)ball_explosion[i].spr=EXPLODE11;
      if(ball_explosion[i].counter>=24&&ball_explosion[i].counter<26)ball_explosion[i].spr=EXPLODE12;
      if(ball_explosion[i].counter>=26&&ball_explosion[i].counter<28)ball_explosion[i].spr=EXPLODE13;
      if(ball_explosion[i].counter>=28&&ball_explosion[i].counter<30)ball_explosion[i].spr=EXPLODE14;
      if(ball_explosion[i].counter>=30&&ball_explosion[i].counter<32)ball_explosion[i].spr=EXPLODE15;
      if(ball_explosion[i].counter>=32&&ball_explosion[i].counter<34)ball_explosion[i].spr=EXPLODE16;
      if(ball_explosion[i].counter>=34&&ball_explosion[i].counter<36)ball_explosion[i].spr=EXPLODE17;
      if(ball_explosion[i].counter>=36&&ball_explosion[i].counter<38)ball_explosion[i].spr=EXPLODE18;
      if(ball_explosion[i].counter>=38&&ball_explosion[i].counter<40)ball_explosion[i].spr=EXPLODE19;
      if(ball_explosion[i].counter>=40&&ball_explosion[i].counter<42)ball_explosion[i].spr=EXPLODE20;
      if(ball_explosion[i].counter>=42&&ball_explosion[i].counter<44)ball_explosion[i].spr=EXPLODE21;
      if(ball_explosion[i].counter>=44&&ball_explosion[i].counter<46)ball_explosion[i].spr=EXPLODE22;
      if(ball_explosion[i].counter>=46&&ball_explosion[i].counter<48)ball_explosion[i].spr=EXPLODE23;
      if(ball_explosion[i].counter>=48&&ball_explosion[i].counter<50)ball_explosion[i].spr=EXPLODE24;
      if(ball_explosion[i].counter>=50&&ball_explosion[i].counter<52)ball_explosion[i].spr=EXPLODE25;
      if(ball_explosion[i].counter>=52&&ball_explosion[i].counter<54)ball_explosion[i].spr=EXPLODE26;
      if(ball_explosion[i].counter>=54&&ball_explosion[i].counter<56)ball_explosion[i].spr=EXPLODE27;
      if(ball_explosion[i].counter>=56&&ball_explosion[i].counter<58)ball_explosion[i].spr=EXPLODE28;
      if(ball_explosion[i].counter>=58&&ball_explosion[i].counter<60)ball_explosion[i].spr=EXPLODE29;
      if(ball_explosion[i].counter>=60&&ball_explosion[i].counter<62)ball_explosion[i].spr=EXPLODE30;
      if(ball_explosion[i].counter>=62&&ball_explosion[i].counter<64)ball_explosion[i].spr=EXPLODE31;
      if(ball_explosion[i].counter>=64&&ball_explosion[i].counter<66)ball_explosion[i].spr=EXPLODE32;
      if(ball_explosion[i].counter>=66&&ball_explosion[i].counter<68)ball_explosion[i].spr=EXPLODE33;
      if(ball_explosion[i].counter>=68&&ball_explosion[i].counter<70)ball_explosion[i].spr=EXPLODE34;
      if(ball_explosion[i].counter>=70&&ball_explosion[i].counter<72)ball_explosion[i].spr=EXPLODE35;
      if(ball_explosion[i].counter>=72&&ball_explosion[i].counter<74)ball_explosion[i].spr=EXPLODE36;
      if(ball_explosion[i].counter>=74&&ball_explosion[i].counter<76)ball_explosion[i].spr=EXPLODE37;
      if(ball_explosion[i].counter>=76&&ball_explosion[i].counter<78)ball_explosion[i].spr=EXPLODE38;
      if(ball_explosion[i].counter>=78&&ball_explosion[i].counter<80)ball_explosion[i].spr=EXPLODE39;
      if(ball_explosion[i].counter>=80&&ball_explosion[i].counter<82)ball_explosion[i].spr=EXPLODE40;
      if(ball_explosion[i].counter>=82&&ball_explosion[i].counter<84)ball_explosion[i].spr=EXPLODE41;
      if(ball_explosion[i].counter>=84){
        ball_explosion[i].x=0;
        ball_explosion[i].y=0;
        ball_explosion[i].alive=0;
        ball_explosion[i].spr=EXPLODE0;
        ball_explosion[i].counter=0;
      }    
     }
    }    
}


void draw_ball_explosion(int amount){ 
  int i;
  if(amount>MAX_BALLS)amount=MAX_BALLS;  
  for(i=0;i<amount;i++){
    if(ball_explosion[i].alive){
        draw_sprite(buffer,(BITMAP *) explode_sprites[ball_explosion[i].spr].dat, ball_explosion[i].x, ball_explosion[i].y);  
    }    
  }    
}

//Enemy related collisions
int tile_col_enemy(struct TILE t,struct enemy p){
    if(t.x1 > p.x2) return 0;
    if(t.x2 < p.x1) return 0;
    if(t.y1 > p.y2) return 0;
    if(t.y2 < p.y1) return 0;
    return 1;
}   

int enemy_col_enemy(struct enemy t,struct enemy p){
    if(t.x1 > p.x2) return 0;
    if(t.x2 < p.x1) return 0;
    if(t.y1 > p.y2) return 0;
    if(t.y2 < p.y1) return 0;
    return 1;
}   

int tile_col_enemy_shot(struct TILE t,struct  enemy_shot s){
    if(t.x1 > s.x2) return 0;
    if(t.x2 < s.x1) return 0;
    if(t.y1 > s.y2) return 0;
    if(t.y2 < s.y1) return 0;
    return 1;
} 

int enemy_col_enemy_shot(struct enemy t,struct  enemy_shot s){
    if(t.x1 > s.x2) return 0;
    if(t.x2 < s.x1) return 0;
    if(t.y1 > s.y2) return 0;
    if(t.y2 < s.y1) return 0;
    return 1;
}

int enemy_shot_col_enemy_shot(struct enemy_shot t,struct  enemy_shot s){
    if(t.x1 > s.x2) return 0;
    if(t.x2 < s.x1) return 0;
    if(t.y1 > s.y2) return 0;
    if(t.y2 < s.y1) return 0;
    return 1;
}
        
#endif
